//
//  JwNavigationController.m
//  JwPack
//
//  Created by 陈警卫 on 2022/8/29.
//

#import "JwNavigationController.h"

@interface JwNavigationController ()

@end

@implementation JwNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    kJwWeak(self);
    self.view.jw_didSkinerBlock = ^(id  _Nonnull sender) {
        [wself jw_skinerBlockAction:sender];
    };
}

/// MARK: 全局项目刷新回调
/// 解决 jw_skinerBlockAction 父类子类实现冲突
- (void)jw_skinerBlockAction:(id)sender {
    self.view.backgroundColor = kJwSkiner.jw_back.color;
    
    [self setupNavBarAppearance];
}

/// 设置 NavigationBar
- (void)setupNavBarAppearance {
    UIColor *backColor = self.jw_navBarBackColor;
    UIColor *tintColor = self.jw_navBarTintColor;
    
    if (!backColor) {
        backColor = [UIColor jw_colorHexString:GV_JwFrame_navBarBackColorString];
    }
    if (!tintColor) {
        tintColor = [UIColor jw_colorHexString:GV_JwFrame_navBarTintColorString];
    }
    [self setupNavBarApperanceWithBackColor:backColor tintColor:tintColor];
}

/// 设置导航栏颜色
- (void)setupNavBarApperanceWithBackColor:(UIColor *)backColor tintColor:(UIColor *)tintColor {
    if (@available(iOS 13.0, *)) {
        UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
        [appearance configureWithTransparentBackground];
        appearance.backgroundColor = backColor;
        appearance.shadowColor = [UIColor clearColor];
        appearance.titleTextAttributes = @{NSForegroundColorAttributeName: tintColor};
        self.navigationBar.standardAppearance = appearance;
        self.navigationBar.scrollEdgeAppearance = appearance;
    } else {
        self.navigationBar.translucent = NO;
        self.navigationBar.barTintColor = backColor;
        self.navigationBar.tintColor = tintColor;
        self.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: tintColor};
        // 去掉底边阴影线
        [self.navigationBar setShadowImage:[UIImage new]];
        [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    }
}

/// 重写Push方法
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.viewControllers.count) {
        viewController.hidesBottomBarWhenPushed = YES;
    }
    [super pushViewController:viewController animated:animated];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
